{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1dfa1980",
   "metadata": {},
   "source": [
    "# 浅拷贝和深度拷贝"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4f81465",
   "metadata": {},
   "source": [
    "浅拷贝"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5d58258b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "({1: [1, 2, 3]}, {1: [1, 2, 3]})"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = {1: [1,2,3]}\n",
    "b = a.copy()\n",
    "a,b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f1e2deb1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "({1: [1, 2, 3, 4]}, {1: [1, 2, 3, 4]})"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[1].append(4)\n",
    "a,b"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e00aa43",
   "metadata": {},
   "source": [
    "深度拷贝 - 完全拷贝了父对象及其子对象， 两者完全独立，其一改变不会引起另一方的改变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "86cb1f68",
   "metadata": {},
   "outputs": [],
   "source": [
    "import copy\n",
    "\n",
    "c = copy.deepcopy(a)\n",
    "a[1].append(5)\n",
    "a,c"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
